<template>
    <div v-loading="loading" class="dialog">
        <div class="title">资源修改/新增</div>
        <el-dialog
            :title="addShow == 1 ? '新增' : '修改'"
            :visible.sync="addShow"
            width="70%"
            append-to-body
        >
            <div style="max-height: 90vh; overflow-y: scroll">
                <AddBdialog
                    ref="addBdialog"
                    :configure="configure"
                    :hosts="form.hosts"
                    :supplierCode="supplierCode"
                    @addTable="addTable"
                />
            </div>
            <div slot="footer" class="dialog-footer">
                <el-button type="primary" @click="$refs.addBdialog.submit()"
                    >确 定</el-button
                >
                <el-button @click="addShow = false">取 消</el-button>
            </div>
        </el-dialog>
       <el-button
            type="primary"
            style="padding: 10px 40px"
            @click="showAdd(1, false)"
            >新增</el-button
        >
        <div class="wrap">
            <div class="wrap_title">
                <div>服务器</div>
            </div>
            <div style="padding: 20px 20px; width: 100%">
                <el-table
                    :data="form.hosts"
                    style="width: 100%; margin-top: 13px"
                >
                    <el-table-column label="资源类型">
                        <template slot-scope="scope">
                            {{
                                scope.row.flavorType == 1
                                    ? "云服务器"
                                    : scope.row.flavorType == 2
                                    ? "高性能服务器"
                                    : scope.row.serverCode
                                    ? "数据库"
                                    : "存储产品"
                            }}
                        </template>
                    </el-table-column>
                    <el-table-column label="实例名称">
                        <template slot-scope="scope">
                            <span v-if="scope.row.flavorType">{{
                                scope.row.hostName
                            }}</span>
                            <span v-else-if="scope.row.serverCode">{{
                                scope.row.hostInstanceName
                            }}</span>
                            <span
                                v-else-if="!scope.row.hostInstanceNames.length"
                            ></span>
                            <div
                                v-else
                                style="margin-bottom: 6px"
                                v-for="(item, index) in scope.row
                                    .hostInstanceNames"
                                :key="index"
                            >
                                {{ item }}
                            </div>
                        </template>
                    </el-table-column>
                    <el-table-column label="资源详情">
                        <template slot-scope="scope">
                            <div
                                v-if="oldform.hosts[scope.$index].flavorType"
                                placement="top-start"
                                width="300"
                                trigger="hover"
                            >
                                <div style="margin-bottom: 6px">
                                    <label>可用域：</label
                                    >{{ oldform.hosts[scope.$index].availableDomain_label }}
                                </div>
                                <div style="margin-bottom: 6px" v-if="oldform.hosts[scope.$index].flavorType != 1">
                                    <label>资源类型：</label>
                                    {{ oldform.hosts[scope.$index].cloudFlavorCode_label }}
                                </div>
                                <div
                                    style="margin-bottom: 6px"
                                    v-if="oldform.hosts[scope.$index].flavorType == 1"
                                >
                                    <label>规格：</label
                                    >
                                    {{ oldform.hosts[scope.$index].cpuNumber }}核vCPU；{{ oldform.hosts[scope.$index].memorySize }}G内存；
                                </div>
                                <div
                                    style="margin-bottom: 6px"
                                    v-if="oldform.hosts[scope.$index].flavorType == 2"
                                >
                                    <label>规格：</label
                                    >{{ oldform.hosts[scope.$index].cloudFlavorCode_desc }}
                                </div>
                                <div
                                    style="margin-bottom: 6px"
                                    v-if="oldform.hosts[scope.$index].flavorType == 1 && oldform.hosts[scope.$index].osDisk"
                                >
                                    <label>系统盘：</label
                                    >{{
                                        oldform.hosts[scope.$index].osDisk?oldform.hosts[scope.$index].osDisk.diskServerCode_label:''
                                    }}，{{ oldform.hosts[scope.$index].osDisk?oldform.hosts[scope.$index].osDisk.dataDiskSize:'' }}GB
                                </div>
                                <div
                                    style="margin-bottom: 6px"
                                >
                                    <label>操作系统：</label
                                    >
                                    <!-- {{ oldform.hosts[scope.$index].osName }} -->
                                    {{oldform.hosts[scope.$index].osName ||osName(oldform.hosts[scope.$index].osServerCode)}}
                                </div>
                                <div style="margin-bottom: 6px" v-if="oldform.hosts[scope.$index].flavorType == 1 && oldform.hosts[scope.$index].disks">
                                    <label>
                                        数据盘(共<span style="color: #e83112">{{
                                            oldform.hosts[scope.$index].disks.length
                                        }}</span
                                        >块){{
                                            oldform.hosts[scope.$index].disks.length ? ":" : ""
                                        }}</label
                                    >
                                </div>
                                <div
                                    style="margin: 0 0 6px 16px"
                                    v-for="(item, index) in oldform.hosts[scope.$index].disks"
                                    :key="index"
                                    v-if="oldform.hosts[scope.$index].flavorType == 1 && oldform.hosts[scope.$index].disks"
                                >
                                    <span>{{ item.diskServerCode_label }}</span
                                    >，{{ item.dataDiskSize }}GB
                                </div>
                            </div>
                        </template>
                    </el-table-column>
                    <el-table-column label="变更后">
                        <template slot-scope="scope">
                          <div v-show="!scope.row">已回收</div>
                            <div v-show="!scope.row.insStatus">未变更</div>
                            <div v-show="(scope.row.insStatus?scope.row.insStatus : '')=='REMOVE'">已删除</div>
                            <div v-show="form.hosts[scope.$index].insStatus=='UPDATE'">
                            <div
                                v-if="scope.row.flavorType"
                                placement="top-start"
                                width="300"
                                trigger="hover"
                            >
                                <div style="margin-bottom: 6px">
                                    <label>可用域：</label
                                    >{{ scope.row.availableDomain_label }}
                                </div>
                                <div style="margin-bottom: 6px" v-if="scope.row.flavorType != 1">
                                    <label>资源类型：</label>
                                    {{ scope.row.cloudFlavorCode_label }}
                                </div>
                                <div
                                    style="margin-bottom: 6px"
                                    v-if="scope.row.flavorType == 1"
                                >
                                    <label>规格：</label
                                    >
                                    {{scope.row.cpuNumber}}vCPU； {{scope.row.memorySize}}G内存
                                </div>
                                <div
                                    style="margin-bottom: 6px"
                                    v-if="scope.row.flavorType == 2"
                                >
                                    <label>规格：</label
                                    >
                                    {{scope.row.cloudFlavorCode_desc}}
                                </div>
                                <div
                                    style="margin-bottom: 6px"
                                    v-if="scope.row.flavorType == 1 && scope.row.osDisk"
                                >
                                    <label>系统盘：</label
                                    >{{
                                        scope.row.osDisk?scope.row.osDisk.diskServerCode_label:''
                                    }}，{{ scope.row.osDisk?scope.row.osDisk.dataDiskSize:'' }}GB
                                </div>
                                <div
                                    style="margin-bottom: 6px"
                                >
                                    <label>操作系统：</label
                                    >
                                    <!-- {{ scope.row.osName }} -->
                                    {{scope.row.osName||osName(scope.row.osServerCode)}}
                                </div>
                                <template v-if="scope.row.flavorType == 1 && scope.row.disks">
                                    <div style="margin-bottom: 6px">
                                        <label>
                                            数据盘(共<span style="color: #e83112">{{
                                                scope.row.disks.length
                                            }}</span
                                            >块){{
                                                scope.row.disks.length ? ":" : ""
                                            }}</label
                                        >
                                    </div>
                                    <div
                                        style="margin: 0 0 6px 16px"
                                        v-for="(item, index) in scope.row.disks"
                                        :key="index"
                                    >
                                        <span>{{ item.diskServerCode_label }}</span
                                        >，{{ item.dataDiskSize }}GB
                                    </div>
                                </template>
                            </div>
                            </div>
                        </template>
                    </el-table-column>
                    <el-table-column
                        label="操作"
                        class-name="small-padding fixed-width"
                    >
                        <template slot-scope="scope">
                            <el-button
                                size="mini"
                                type="text"
                                icon="el-icon-edit-outline"
                                v-show="scope.row.insStatus!='REMOVE'"
                                @click="showAdd(2, scope.row, scope.$index)"
                                >修改
                            </el-button>
                            <el-button
                                size="mini"
                                type="text"
                                icon="el-icon-delete"
                                v-show="scope.row.insStatus!='REMOVE'"
                                @click="del(scope.row, scope.$index,1)"
                                >删除
                              </el-button>
                              <el-button
                                size="mini"
                                type="text"
                                icon="el-icon-refresh-left"
                                v-show="scope.row.insStatus!='ADD'"
                                @click="huanyuan(scope.row, scope.$index,1)"
                                >还原
                              </el-button>
                        </template>
                    </el-table-column>
                </el-table>
            </div>
        </div>
        <div class="wrap">
            <div class="wrap_title">
                <div>数据库</div>
            </div>
            <div style="padding: 20px 20px; width: 100%">
                <el-table
                    :data="form.databases"
                    style="width: 100%; margin-top: 13px"
                >
                    <el-table-column label="版本">
                        <template slot-scope="scope">
                            <span>{{ scope.row.serverName }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="资源详情">
                        <template slot-scope="scope">
                            <div
                                placement="top-start"
                                width="300"
                                trigger="hover"
                            >
                                <div style="margin-bottom: 6px">
                                    <label>类型：</label
                                    >{{ oldform.databases[scope.$index].serverCode_label }}
                                </div>
                                <!-- <div style="margin-bottom: 6px">
                                    <label>版本：</label
                                    >{{ oldform.databases[scope.$index].databaseVersion }}
                                </div> -->
                                <div style="margin-bottom: 6px">
                                    <label>位数：</label
                                    >{{ oldform.databases[scope.$index].systemDigits }}
                                </div>
                            </div>
                        </template>
                    </el-table-column>
                    <el-table-column label="变更后">
                        <template slot-scope="scope">
                          <div v-show="!scope.row">已回收</div>
                          <div v-show="!scope.row.insStatus">未变更</div>
                          <div v-show="(scope.row.insStatus?scope.row.insStatus : '')=='REMOVE'">已删除</div>
                          <div  v-show="form.databases[scope.$index].insStatus=='UPDATE'">
                            <div
                                placement="top-start"
                                width="300"
                                trigger="hover"
                            >
                                <div style="margin-bottom: 6px">
                                    <label>类型：</label
                                    >{{ scope.row.serverName||scope.row.serverCode}}
                                </div>
                                <!-- <div style="margin-bottom: 6px">
                                    <label>版本：</label
                                    >{{ scope.row.databaseVersion }}
                                </div> -->
                                <div style="margin-bottom: 6px">
                                    <label>位数：</label
                                    >{{ scope.row.systemDigits }}
                                </div>
                            </div>
                            </div>
                        </template>
                    </el-table-column>
                    <el-table-column
                        label="操作"
                        class-name="small-padding fixed-width"
                    >
                        <template slot-scope="scope">
                            <el-button
                                size="mini"
                                type="text"
                                icon="el-icon-edit-outline"
                                v-show="scope.row.insStatus!='REMOVE'"
                                @click="showAdd(2, scope.row, scope.$index)"
                                >修改
                            </el-button>
                            <el-button
                                size="mini"
                                type="text"
                                icon="el-icon-delete"
                                v-show="scope.row.insStatus!='REMOVE'"
                                @click="del(scope.row, scope.$index,2)"
                                >删除
                              </el-button>
                              <el-button
                                size="mini"
                                type="text"
                                icon="el-icon-refresh-left"
                                v-show="scope.row.insStatus!='ADD'"
                                @click="huanyuan(scope.row, scope.$index,2)"
                                >还原
                              </el-button>


                        </template>
                    </el-table-column>
                </el-table>
            </div>
        </div>
        <div class="wrap">
            <div class="wrap_title">
                <div>存储产品</div>
            </div>
            <div style="padding: 20px 20px; width: 100%">
                <el-table
                    :data="form.storeProducts"
                    style="width: 100%; margin-top: 13px"
                >
                    <el-table-column label="磁盘类型">
                        <template slot-scope="scope">
                            <!-- {{ scope.row.diskServerCode_label }} -->
                            {{ oldform.storeProducts[scope.$index].diskServerName }}
                        </template>
                    </el-table-column>
                    <el-table-column label="磁盘用量">
                        <template slot-scope="scope">
                            <!-- <span> {{ scope.row.dataDiskSize }}GB </span> -->
                            {{ oldform.storeProducts[scope.$index].dataDiskSize }}GB
                        </template>
                    </el-table-column>
                    <el-table-column label="资源详情">
                        <template slot-scope="scope">
                            <div
                                placement="top-start"
                                width="300"
                                trigger="hover"
                            >
                                <div style="margin-bottom: 6px">
                                    <label>存储类型：</label
                                    >{{ oldform.storeProducts[scope.$index].productCode }}
                                </div>
                                <div style="margin-bottom: 6px">
                                    <label>服务类型：</label
                                    >{{ oldform.storeProducts[scope.$index].diskCode }}
                                </div>
                                <div style="margin-bottom: 6px">
                                    <label>磁盘类型：</label
                                    >{{ oldform.storeProducts[scope.$index].diskServerName }}
                                </div>
                                <div style="margin-bottom: 6px">
                                    <label>磁盘用量：</label
                                    >{{ oldform.storeProducts[scope.$index].dataDiskSize }}GB
                                </div>
                                <div style="margin-bottom: 6px">
                                    <label>服务器：</label>
                                     <div v-for="item in oldform.storeProducts[scope.$index].hostIds"> {{gethostName(item)}}</div>
                                </div>
                            </div>
                        </template>
                    </el-table-column>
                    <el-table-column label="变更后">
                        <template slot-scope="scope">
                          <div v-show="!scope.row">已回收</div>
                          <div v-show="!scope.row.insStatus">未变更</div>
                          <div v-show="(scope.row.insStatus?scope.row.insStatus : '')=='REMOVE'">已删除</div>
                          <div  v-show="form.storeProducts[scope.$index].insStatus=='UPDATE'">
                            <div
                                placement="top-start"
                                width="300"
                                trigger="hover"
                            >
                                <div style="margin-bottom: 6px">
                                    <label>存储类型：</label
                                    >{{ scope.row.productCode }}
                                </div>
                                <div style="margin-bottom: 6px">
                                    <label>服务类型：</label
                                    >{{ scope.row.diskCode }}
                                </div>
                                <div style="margin-bottom: 6px">
                                    <label>磁盘类型：</label
                                    >{{ scope.row.diskServerCode_label||scope.row.diskServerName }}
                                </div>
                                <div>
                                    <label>磁盘用量：</label
                                    >{{ scope.row.dataDiskSize }}GB
                                </div>
                                <div style="margin-bottom: 6px">
                                    <label>服务器：</label>
                                     <div v-for="item in  scope.row.hostIds"> {{gethostName(item)}}</div>
                                </div>
                            </div>
                            </div>
                        </template>
                    </el-table-column>
                    <el-table-column
                        label="操作"
                        class-name="small-padding fixed-width"
                    >
                        <template slot-scope="scope">
                            <el-button
                                size="mini"
                                type="text"
                                icon="el-icon-edit-outline"
                                v-show="scope.row.insStatus!='REMOVE'"
                                @click="showAdd(2, scope.row, scope.$index)"
                                >修改
                            </el-button>
                            <el-button
                                size="mini"
                                type="text"
                                icon="el-icon-delete"
                                v-show="scope.row.insStatus!='REMOVE'"
                                @click="del(scope.row, scope.$index,3)"
                                >删除
                              </el-button>
                              <el-button
                                size="mini"
                                type="text"
                                icon="el-icon-refresh-left"
                                v-show="scope.row.insStatus!='ADD'"
                                @click="huanyuan(scope.row, scope.$index,3)"
                                >还原
                              </el-button>
                        </template>
                    </el-table-column>
                </el-table>
            </div>
        </div>


        <div class="wrap">
            <div class="wrap_title">
                <div>安全产品</div>
            </div>
            <div style="padding: 20px 20px; width: 100%">
              <el-table
                  :data="[].concat(form.safeProductsList)"
                  style="width: 100%; margin-top: 13px"
              >
              <el-table-column label="序号" width="60px">
                <template slot-scope="scope">
                  {{scope.$index+1}}
                </template>
              </el-table-column>
                  <el-table-column label="产品名称">
                      <template slot-scope="scope">
                          {{ scope.row.productName }}
                      </template>
                  </el-table-column>
                   <el-table-column label="数量">
                      <template slot-scope="scope">
                          {{ scope.row.num }}
                      </template>
                  </el-table-column>
                  <el-table-column
                      label="操作"
                      class-name="small-padding fixed-width"
                      v-if="form.confirmed == false"
                  >
                      <template slot-scope="scope">
                          <el-button
                              size="mini"
                              type="text"
                              icon="el-icon-edit-outline"
                              @click="editSafe(scope.$index)"
                              >修改</el-button
                          >
                      </template>
                  </el-table-column>
              </el-table>
               <!-- <el-table
                    :data="form.safeProducts"
                    style="width: 100%; margin-top: 13px"
                >
                    <el-table-column label="产品名称">
                        <template slot-scope="scope">
                            {{ scope.row.productName}}
                        </template>
                    </el-table-column>
                    <el-table-column
                        label="操作"
                        class-name="small-padding fixed-width"
                    >
                        <template slot-scope="scope">
                            <el-button
                                size="mini"
                                type="text"
                                icon="el-icon-delete"
                                v-show="scope.row.insStatus!='REMOVE'"
                                @click="del(scope.row, scope.$index,4)"
                                >删除
                              </el-button>
                              <el-button
                                size="mini"
                                type="text"
                                icon="el-icon-refresh-left"
                                v-show="scope.row.insStatus!='ADD'"
                                @click="huanyuan(scope.row, scope.$index,4)"
                                >还原
                              </el-button>
                        </template>
                    </el-table-column>
                </el-table> -->
            </div>
        </div>
        <div class="wrap" v-if="false">
            <div class="wrap_title">
                <div>其他</div>
            </div>
            <div style="padding: 10px 20px">
                <div class="wrap_item" style="margin-top: 0">
                    <div style="line-height: 28px">说明:</div>
                    <div style="width: 500px">
                        <el-input
                            type="textarea"
                            style="width: 100%"
                            :autosize="{ minRows: 2, maxRows: 4 }"
                            placeholder="请输入说明"
                            v-model="form.remark"
                        >
                        </el-input>
                    </div>
                </div>
                <div class="wrap_item">
                    <div style="line-height: 28px">文件:</div>
                    <el-upload
                        class="upload-demo"
                        style="display: block;"
                        accept
                        list-type="picture"
                        :show-file-list="false"
                        ref="upload"
                        :file-list="form.fileList"
                        action=""
                        :on-preview="handlePictureCardPreview"
                        :on-remove="handleChange"
                        :on-change="handleChange"
                        :auto-upload="false"
                    >
                        <el-button slot="trigger" size="small" type="primary">选取文件</el-button>
                    </el-upload>
                    <el-table
                        v-if="fileListState"
                        :data="form.fileList"
                        style="margin-left:20px;width: 50vw">
                        <el-table-column
                            label="文件名称"
                            >
                            <template slot-scope="scope">
                                {{scope.row.name.substring( 0 ,scope.row.name.lastIndexOf("."))}}
                            </template>
                        </el-table-column>
                        <el-table-column
                            label="文件类型"
                            >
                            <template slot-scope="scope">
                                {{scope.row.name.substring(scope.row.name.lastIndexOf(".") + 1,scope.row.name.length)}}
                            </template>
                        </el-table-column>
                        <el-table-column
                                label="操作"
                                width="100"
                                class-name="small-padding fixed-width"
                            >
                                <template slot-scope="scope">
                                    <el-button
                                        size="mini"
                                        type="text"
                                        icon="el-icon-view"
                                        @click="previewFile(scope.row)"
                                        >预览
                                    </el-button>
                                    <el-button
                                        size="mini"
                                        type="text"
                                        icon="el-icon-delete"
                                        @click="DeleteFile(scope.row,scope.$index)"
                                        >删除
                                    </el-button>
                                </template>
                            </el-table-column>
                    </el-table>
                </div>
            </div>
        </div>
        <el-dialog :visible.sync="dialogVisible">
            <div style="max-height: 90vh; overflow-y: scroll">
                <img width="100%" :src="dialogImageUrl" alt="" />
            </div>
        </el-dialog>
    </div>
</template>

<script>
import AddBdialog from "./addBdialog.vue";
import { hosts } from "@/api/cloud/cloud";
import { uploadFile } from "@/api/system/upload.js";
import { getResourcesByCloudUpId } from "@/api/resources/change.js";
import { v4 as uuidv4 } from "uuid";
export default {
    name: "addB",
    components: {
        AddBdialog,
    },
    props: {
        configure: {
            type: Object,
            default: {},
        },
        supplierCode:{
            type:String,
            default:'',
        },
    },
    data() {
        return {
            loading:false,
            addShow: false,
            index: 0,
            yyaqList: null,
            //旧数据
            oldform:{
                cloudSupplier: undefined, //服务商
                hosts: [], //服务器列表
                databases: [], //数据库列表
                storeProducts: [], //存储产品列表
                safeProducts: [], //安全产品真实数据
                remark: "", //说明
                fileList: [],
            },
            fileListState : true,
            oldform:null,
            // 数据
            form: {
                cloudSupplier: undefined, //服务商
                hosts: [], //服务器列表
                databases: [], //数据库列表
                storeProducts: [], //存储产品列表
                safeProducts: [], //安全产品真实数据
                remark: "", //说明
                fileList: [],
            },
            dialogImageUrl: "",
            dialogVisible: false,
            SelectedcloudServiceName: "",
            SelectedcloudService: "",
            cloudUpId: "",
            // 暂时上级传递的主机数据
            hosts: [],
            hostsIndex: 0,
        };
    },
    created() {},
    methods: {
      gethostName(id){
        let name =''
        this.form.hosts.some(item=>{
          if(item.id==id){
            name=item.hostName
            return true
          }
        })
        return name
      },
      editSafe(index){
        this.$prompt('请输入数量','', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
        inputValue:this.form.safeProductsList[index].num,
        }).then((resp) => {
			if(!isNaN(resp.value)&&parseInt(resp.value)>=0) {
				this.form.safeProductsList[index].num=parseInt(resp.value)
            // this.NotModifyState=true
			}
       })
      },
        osName(code){
            let serviceName
            this.configure.czxtList.forEach(item=>{
                if(item.code == code){
                    serviceName = item.serviceName
                }
            })
            return serviceName
        },
        init(data){
          if(this.oldform){
            return
          }

          data.safeProductsList=[]
          let aqchecked=[]
          for(let key in data.safeProducts){
            data.safeProductsList.push({productName:key,num:data.safeProducts[key].length})
            aqchecked.push(data.safeProducts[key][0].productCode)
          }
          // detail.safeProducts.forEach(data=>{
          //       aqchecked.push(data.productCode)
          // })
          let detail = data;
          // detail.storeProducts.forEach((data) => {
          //     this.configure[
          //         data.productCode == "共享型" ? "ccList" : "fwcpList"
          //     ].some((it) => {
          //         if (it.code == data.diskServerCode) {
          //             data.diskServerCode_label = it.serviceName;
          //             return true;
          //         }
          //     });
          //     data.hostInstanceNames = [];
          //     if (data.hosts) {
          //         data.hostIds=[]
          //         data.hosts.forEach((item) => {
          //             data.hostIds.push(item.id)
          //             data.hostInstanceNames.push(item.instanceName);
          //         });
          //     }
          // });
          detail.databases.forEach((data) => {
              this.configure.sjkList.some((it) => {
                  if (it.code == data.serverCode) {
                      data.serverCode_label = it.serviceName;
                      return true;
                  }
              });
          });
          detail.hosts.forEach((data) => {
              data.hostName = data.instanceName;
              //可用域
              this.configure.available_domain.some((item) => {
                  if (item.dictValue == data.availableDomain) {
                      data.availableDomain_label = item.dictLabel;
                      return true;
                  }
              });
              //系统盘类型
              if (data.osDisk) {
                  this.configure.storage_type.some((item) => {
                      if (item.code == data.osDisk.diskServerCode) {
                          data.osDisk.diskServerCode_label =
                              item.serviceName;
                          return true;
                      }
                  });
              }
              //数据盘类型
              if (data.disks) {
                  data.disks.forEach((item) => {
                      this.configure.ccList.some((it) => {
                          if (it.code == item.diskServerCode) {
                              item.diskServerCode_label = it.serviceName;
                              return true;
                          }
                      });
                  });
              } else {
                  data.disks = [];
              }
              //规格
              if (data.flavorType == 1) {
                  this.configure.codeList.some((item) => {
                      if (item.specCode == data.cloudFlavorCode) {
                          data.cloudFlavorCode_label = item.specName;
                          data.cloudFlavorCode_desc = item.desc;
                          return true;
                      }
                  });
              }
              if (data.flavorType == 2) {
                  this.configure.wlfwqList.some((item) => {
                      if (item.code == data.cloudFlavorCode) {
                          data.cloudFlavorCode_label = item.serviceName;
                          data.cloudFlavorCode_desc = item.remark;
                          return true;
                      }
                  });
              }
          });

          detail.aqchecked=aqchecked
          this.form =JSON.parse(JSON.stringify(detail));
          this.oldform =JSON.parse(JSON.stringify(detail));
        },
      // init2(n) {
      //   getResourcesByCloudUpId(n.id).then(res=>{
      //         let detail = res.data;
      //         detail.storeProducts.forEach((data) => {
      //             this.configure[
      //                 data.productCode == "共享型" ? "ccList" : "fwcpList"
      //             ].some((it) => {
      //                 if (it.code == data.diskServerCode) {
      //                     data.diskServerCode_label = it.serviceName;
      //                     return true;
      //                 }
      //             });
      //             data.hostInstanceNames = [];
      //             if (data.hosts) {
      //                 data.hostIds=[]
      //                 data.hosts.forEach((item) => {
      //                     data.hostIds.push(item.id)
      //                     data.hostInstanceNames.push(item.instanceName);
      //                 });
      //             }
      //         });
      //         detail.databases.forEach((data) => {
      //             this.configure.sjkList.some((it) => {
      //                 if (it.code == data.serverCode) {
      //                     data.serverCode_label = it.serviceName;
      //                     return true;
      //                 }
      //             });
      //         });
      //         detail.hosts.forEach((data) => {
      //             data.hostName = data.instanceName;
      //             //可用域
      //             this.configure.available_domain.some((item) => {
      //                 if (item.dictValue == data.availableDomain) {
      //                     data.availableDomain_label = item.dictLabel;
      //                     return true;
      //                 }
      //             });
      //             //系统盘类型
      //             if (data.osDisk) {
      //                 this.configure.storage_type.some((item) => {
      //                     if (item.code == data.osDisk.diskServerCode) {
      //                         data.osDisk.diskServerCode_label =
      //                             item.serviceName;
      //                         return true;
      //                     }
      //                 });
      //             }
      //             //数据盘类型
      //             if (data.disks) {
      //                 data.disks.forEach((item) => {
      //                     this.configure.ccList.some((it) => {
      //                         if (it.code == item.diskServerCode) {
      //                             item.diskServerCode_label = it.serviceName;
      //                             return true;
      //                         }
      //                     });
      //                 });
      //             } else {
      //                 data.disks = [];
      //             }
      //             //规格
      //             if (data.flavorType == 1) {
      //                 this.configure.codeList.some((item) => {
      //                     if (item.specCode == data.cloudFlavorCode) {
      //                         data.cloudFlavorCode_label = item.specName;
      //                         data.cloudFlavorCode_desc = item.desc;
      //                         return true;
      //                     }
      //                 });
      //             }
      //             if (data.flavorType == 2) {
      //                 this.configure.wlfwqList.some((item) => {
      //                     if (item.code == data.cloudFlavorCode) {
      //                         data.cloudFlavorCode_label = item.serviceName;
      //                         data.cloudFlavorCode_desc = item.remark;
      //                         return true;
      //                     }
      //                 });
      //             }
      //         });
      //         let aqchecked=[]
      //         detail.safeProducts.forEach(data=>{
      //               aqchecked.push(data.productCode)
      //         })
      //         detail.aqchecked=aqchecked
      //         this.form =JSON.parse(JSON.stringify(detail));
      //         this.oldform =JSON.parse(JSON.stringify(detail));
      //         this.loading = false
      //   })
      // },
      previewFile(item){
            if(item.name.substring(item.name.lastIndexOf(".") + 1,item.name.length) == 'gif' ||
                item.name.substring(item.name.lastIndexOf(".") + 1,item.name.length) == 'jpeg' ||
                item.name.substring(item.name.lastIndexOf(".") + 1,item.name.length) == 'jpg'){
                    this.dialogImageUrl = item.url;
                    this.dialogVisible = true;
                    return
            }else{
                this.$message.error(`仅限后缀名为 gif、jpeg、jpg 可预览`);
            }
        },
        DeleteFile(data,index){
            this.fileListState = false
            this.form.fileList = this.form.fileList.filter(item=>{
                if(item.uid == data.uid){

                }else{
                return item
                }
            })
            this.fileListState = true
        },
        //文件预览
        handlePictureCardPreview(file) {
            this.dialogImageUrl = file.url;
            this.dialogVisible = true;
        },
        //文件列表变化
        handleChange(res, fileList) {
            this.fileListState = false
            this.form.fileList = fileList;
            this.fileListState = true
            // if (this.form.fileList.length) {
            //     let type = this.form.fileList[this.form.fileList.length - 1].raw
            //         .type;
            //     if (type != "image/jpeg" && type != "image/png") {
            //         this.$message.error(`请选择图片文件`);
            //         this.form.fileList.splice(this.form.fileList.length - 1, 1);
            //     }
            // }
        },
        next() {
            let form=JSON.parse(JSON.stringify(this.form))
            form.oldform=this.oldform
            form.fileList=this.form.fileList
            this.$emit("next",form);
        },
        //添加修改表格
        addTable(data) {
            data = JSON.parse(JSON.stringify(data));
            if(!data.addFlag){
              data.insStatus='UPDATE'
            }
            console.log(data,'erer')
            if (data.flavorType) {
                this.addHosts(data);
            } else if (data.serverCode) {
                this.addDatabases(data);
            } else {
                this.addStoreProducts(data);
            }
        },
        //添加存储产品列表
        addStoreProducts(data) {
            this.configure[
                data.productCode == "共享型" ? "ccList" : "fwcpList"
            ].some((it) => {
                if (it.code == data.diskServerCode) {
                    data.diskServerCode_label = it.serviceName;
                    return true;
                }
            });
            let storeProducts = JSON.parse(
                JSON.stringify(this.form.storeProducts)
            );
            if (this.addShow == 2) {
                storeProducts[this.index] = data;
            } else {
                data.id=uuidv4();
                storeProducts.push(data);
                this.oldform.storeProducts.push(data);
            }
            this.form.storeProducts = storeProducts;
            this.addShow = false;
        },
        //添加修改数据库列表
        addDatabases(data) {
          console.log(data,'xxxxx',this.configure.sjkList)
            //数据库类型
            this.configure.sjkList.some((it) => {
                if (it.code == data.serverCode) {
                    data.serverCode_label = it.serviceName;
                    return true;
                }
            });
            let databases = JSON.parse(JSON.stringify(this.form.databases));
            if (this.addShow == 2) {
                databases[this.index] = data;
            } else {
              data.id=uuidv4();
                databases.push(data);
                this.oldform.databases.push(data);
            }
            this.form.databases = databases;
            this.addShow = false;
        },
        //添加修改服务器列表
        addHosts(data) {
            //可用域
            this.configure.available_domain.some((item) => {
                if (item.dictValue == data.availableDomain) {
                    data.availableDomain_label = item.dictLabel;
                    return true;
                }
            });
            // this.configure.codeList.some((item) => {
            //     if (data.cloudFlavorCode == item.specCode) {
            //         item.details.forEach((it) => {
            //             if (it.serviceCode == "vcpu") {
            //                 data.cpuNumber = it.serviceCount;
            //                 data.cpuServerCode = it.serviceCode;
            //             }
            //             if (it.serviceCode == "memory") {
            //                 data.memorySize = it.serviceCount;
            //                 data.memoryServerCode = it.serviceCode;
            //             }
            //         });
            //         return;
            //     }
            // });
            //数据盘类型
            if(data.disks){
                data.disks.forEach((item) => {
                    this.configure.ccList.some((it) => {
                        if (it.code == item.diskServerCode) {
                            item.diskServerCode_label = it.serviceName;
                            return true;
                        }
                    });
                });
            }
            if (data.flavorType == 1) {
                //系统盘类型
                if(data.osDisk){
                    this.configure.storage_type.some((item) => {
                        if (item.code == data.osDisk.diskServerCode) {
                            data.osDisk.diskServerCode_label = item.serviceName;
                            return true;
                        }
                    });
                }
                //规格
                this.configure.codeList.some((item) => {
                    if (item.specCode == data.cloudFlavorCode) {
                        data.cloudFlavorCode_label = item.specName;
                        data.cloudFlavorCode_desc = item.desc;
                        return true;
                    }
                });
            }
            if (data.flavorType == 2) {
                this.configure.wlfwqList.some((item) => {
                    if (item.code == data.cloudFlavorCode) {
                        data.cloudFlavorCode_label = item.serviceName;
                        data.cloudFlavorCode_desc = item.remark;
                        return true;
                    }
                });
            }
            let hosts = JSON.parse(JSON.stringify(this.form.hosts));
            if (this.addShow == 2) {
                if (
                    data.hostName &&
                    data.hostName == data.instanceName //+ "_" + data.num
                ) {
                    hosts[this.index] = data;
                    this.hosts[
                        Number(this.index) + Number(this.hostsIndex)
                    ] = data; //新增公共服务器+历史服务器
                } else {
                    hosts.splice(this.index, 1);
                    this.hosts.splice(
                        Number(this.index) + Number(this.hostsIndex),
                        1
                    );
                    let sum = 0;
                    hosts.forEach((item) => {
                        if (
                            item.instanceName == data.instanceName &&
                            item.num > sum
                        ) {
                            sum = item.num;
                        }
                    });
                    ////新增公共服务器+历史服务器
                    this.hosts.forEach((item) => {
                        if (
                            item.instanceName == data.instanceName &&
                            item.num > sum
                        ) {
                            sum = item.num;
                        }
                    });
                    data.num = sum + 1;
                    data.hostName = data.instanceName //+ "_" + data.num;
                    hosts.push(data);
                    //新增公共服务器+历史服务器
                    this.hosts.push(data);
                }
            } else {
                let num = Number(data.instanceNum);
                data.instanceNum = 1;
                let sum = 0;
                hosts.forEach((item) => {
                    if (
                        item.instanceName == data.instanceName &&
                        item.num > sum
                    ) {
                        sum = item.num;
                    }
                });
                //新增公共服务器+历史服务器
                this.hosts.forEach((item) => {
                    if (
                        item.instanceName == data.instanceName &&
                        item.num > sum
                    ) {
                        sum = item.num;
                    }
                });
                for (let i = 0; i < num; i++) {
                    let temp = JSON.parse(JSON.stringify(data));
                    if (!temp.num) {
                        temp.num = sum + i + 1;
                    }
                    temp.id=uuidv4();
                    temp.hostName = temp.instanceName //+ "_" + temp.num;
                    hosts.push(temp);
                    this.oldform.hosts.push(temp);
                    this.hosts.push(temp);
                }
            }
            this.form.hosts = hosts;
            this.addShow = false;
        },
        //显示弹窗
        showAdd(num, data, index) {
            this.index = index;
            this.addShow = num;
            setTimeout(() => {
                this.$refs.addBdialog.init(num==2?JSON.parse(JSON.stringify(data)):false);
            }, 200);
        },
        huanyuan(data, index,num){
          let form=JSON.parse(JSON.stringify(this.form))
          if(num==1){
            form.hosts[index]=this.oldform.hosts[index]
          }else if (num==2) {
              let flag=form.hosts.some(item=>{
                  return item.id==data.hostId&&item.insStatus!='REMOVE'
              })
              if(flag){
                form.databases[index]=this.oldform.databases[index]
              }else{
                this.$message({
                  type: "error",
                  message: "请先还原相关服务器",
                });
              }
          } else if (num==3){
              if(!data.hostIds){
                form.storeProducts[index]=this.oldform.storeProducts[index]
              }else{
                let flag=false
                flag=form.hosts.some(item=>{
                    if(data.hostIds.indexOf(item.id)>-1&&item.insStatus=='REMOVE'){
                      return true
                    }else{
                      return false
                    }
                })
                if(flag){
                  this.$message({
                    type: "error",
                    message: "请先还原相关服务器",
                  });
                }else{
                  form.storeProducts[index]=this.oldform.storeProducts[index]
                }
              }
          }else{
              form.safeProducts[index]=this.oldform.safeProducts[index]
          }
          this.form=form
        },
        //删除
        del(data, index,num) {
            let form=JSON.parse(JSON.stringify(this.form))
            if(num==1){
             form.hosts[index].insStatus='REMOVE';
             form.databases.forEach((item) => {
                 if(item.hostId == data.id){
                   item.insStatus='REMOVE'
                 }
             });
             form.storeProducts.forEach((item) => {
                 if(item.hostIds&&item.hostIds.indexOf(data.id) > -1){
                   item.insStatus='REMOVE'
                 }
             });
            }else if (num==2) {
                form.databases[index].insStatus='REMOVE';
            } else if (num==3){
                form.storeProducts[index].insStatus='REMOVE';
            }else{
              form.safeProducts[index].insStatus='REMOVE';
            }
            this.form=form
        },
    },
};
</script>
<style>
.el-form-item--medium .el-form-item__label {
    text-align: left !important;
}
</style>
<style scoped lang="less">
.dialog {
    margin-bottom: 30px;
    font-size: 12px;

    .title {
        text-align: left;
        margin-bottom: 20px;
        font-size: 16px;
        font-weight: bold;
        padding-left: 4px;
        border-left: 4px solid #38b3aa;
    }
    .wrap {
        display: flex;
        background: #faf9ff;
        margin-top: 20px;
        border-radius: 10px;
        .wrap_title {
            padding: 0 10px;
            background: #f4f4f4;
            border-top-left-radius: 10px;
            border-bottom-left-radius: 10px;
            div {
                height: 100%;
                width: 14px;
                font-weight: bold;
                display: flex;
                flex-direction: column;
                justify-content: center;
            }
        }
        .wrap_item {
            display: flex;
            margin-top: 20px;

            div:first-child {
                width: 90px;
                font-weight: bold;
            }
            i {
                line-height: 28px;
                margin-right: 10px;
                font-size: 20px;
                color: #e83112;
            }
        }
    }
    .msg {
        padding: 0 20px 20px 0px;
        background: #faf9ff;
        display: flex;
        flex-wrap: wrap;
        margin-bottom: 30px;
        border-radius: 10px;

        .wra2p {
            width: 100%;
            display: flex;
            flex-wrap: wrap;
        }

        .item {
            margin-left: 20px;
            width: calc(33.33% - 20px);
            min-width: 340px;
            display: flex;
        }
    }
}
</style>
